<!--
forked from Meteor's accounts-ui from
https://github.com/meteor/meteor/tree/ab9ef40d258bbb9b9de453600495c8337577c565/packages/accounts-ui-unstyled

========================================
Meteor is licensed under the MIT License
========================================

Copyright (C) 2011-2015 Meteor Development Group

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


====================================================================
This license applies to all code in Meteor that is not an externally
maintained library. Externally maintained libraries have their own
licenses, included in the LICENSES directory.
====================================================================
-->

<template name="loginButtons">
{{#let txt="accounts.loginButtons.loginButtons"}}
  {{!-- Data context is an instance of AccountsUi. --}}
  {{#if isDemoUser}}
    <button class="show-popup">{{_ (con txt "createButton")}} ▾</button>
  {{else}}
    <button class="show-popup">{{_ (con txt "signInButton")}} ▾</button>
  {{/if}}
{{/let}}
</template>

<template name="accountButtons">
  {{#with profileData}}
    {{#if loading}}
      <button class="show-popup has-picture">{{_ "accounts.loginButtons.accountButtons.loading"}}</button>
    {{else}}
      <button class="show-popup has-picture">
        <span class="profile-picture" style="background-image: url('{{pictureUrl}}');"></span>
        {{displayName}} ▾
      </button>
    {{/if}}
  {{/with}}
</template>

<template name="loginButtonsPopup">
  {{!-- Data context is an instance of AccountsUi. --}}
  {{> _loginButtonsLoggedOutDropdown . }}
</template>

<template name="accountButtonsPopup">
  {{> _loginButtonsLoggedInDropdown . }}
</template>

<template name="_loginButtonsMessages">
  {{#if errorMessage}}
    <p class="message error-message" role="menuitem" aria-disabled="true">{{errorMessage}}</p>
  {{/if}}
  {{#if infoMessage}}
    <p class="message info-message" role="menuitem" aria-disabled="true">{{infoMessage}}</p>
  {{/if}}
</template>

<template name="_loginButtonsLoggedInDropdown">
{{#let txt="accounts.loginButtons._loginButtonsLoggedInDropdown"}}
  <h4>{{_ (con txt "title")}}</h4>

  <div class="account-buttons-list" role="menu">
    {{#linkTo route="account" role="menuitem"}}
      {{_ "accounts.title"}}
    {{/linkTo}}
    {{#if isInApp}}
      {{#if isIncognito}}
        <button class="leave-incognito">{{_ (con txt "revealIdentity")}}</button>
      {{/if}}
    {{/if}}
    {{#if isAdmin}}
      {{#linkTo route="newAdminRoot" role="menuitem"}}{{_ "admin.admin.newAdmin.title"}}{{/linkTo}}
    {{/if}}

    {{#if showSendFeedback}}
      <a href="https://github.com/sandstorm-io/sandstorm/issues" target="_blank" role="menuitem">{{_ (con txt "sendFeedback")}}</a>
    {{/if}}

    {{#if referralsEnabled }}
      {{#if showReferrals}}
        {{!-- should be "shell.referrals.title" --}}
        {{#linkTo route="referrals" role="menuitem"}}{{_ "accounts.loginButtons._loginButtonsLoggedInDropdown.referralProgram"}}{{/linkTo}}
      {{/if}}
    {{/if}}
    {{#if showAbout}}
      {{#linkTo route="about" role="menuitem"}}{{_ "shell.about.title"}}{{/linkTo}}
    {{/if}}

    <button class="logout" role="menuitem">
      {{_ (con txt "signOutButton")}}
    </button>
  </div>
{{/let}}
</template>

<template name="_loginButtonsLoggedOutDropdown">
{{#let txt="accounts.loginButtons._loginButtonsLoggedOutDropdown"}}
  {{#if isDemoUser}}
    <h4>{{_ (con txt "demo.title")}}</h4>
    <p class="demo-note">{{_ (con txt "demo.explanation")}}</p>
    {{> loginButtonsList . }}
  {{else}}
    <h4>{{_ (con txt "title")}}</h4>
    {{#if isCurrentRoute 'shared'}}
      <p class="demo-note">{{_ (con txt "shared.explanation")}}</p>
      {{#if choseLogin}}
        {{> loginButtonsList . }}
      {{else}}
        <div class="login-suggestion" role="menu">
          <button class="login" role="menuitem">
            {{_ (con txt "signInButton")}}
          </button>
          <button class="dismiss" role="menuitem">
            {{_ (con txt "anonymousButton")}}
          </button>
        </div>
      {{/if}}
    {{else}}
      {{> loginButtonsList . }}
    {{/if}}
  {{/if}}
{{/let}}
</template>

<template name="loginButtonsDialog">
{{!-- takes arguments:
  accountsUi: instance of AccountsUi
       label: optional String which replaces top-of-dialog-label.  If absent, the dialog will show
              either "Create account" if the server allows uninvited users or "Sign in" if not.
--}}
  <div class="login-dialog">
    {{!-- There's no actual difference between signing "up" and "in", but people expect there to
          be a difference, so humor them by making the front-page login say "sign up". (But for a
          private server, don't offer "sign up".) --}}
    <h4>
      <span class="logo" style="background-image: url('{{logoUrl}}')"></span>
      {{ labelOrFallback }}
    </h4>

    {{> loginButtonsList accountsUi }}
  </div>
</template>

<template name="loginButtonsList">
  <div class="login-buttons-list">
  {{#each services}}
    {{#with data=loginTemplate.data linkingNewCredential=linkingNewCredential}}
      {{> Template.dynamic template=../loginTemplate.name }}
    {{/with}}
  {{else}}
    {{#linkTo route="newAdminLogin" class="troubleshooting"}}
      {{_ "accounts.loginButtons.loginButtonsList.configure"}}
    {{/linkTo}}
  {{/each}}

  {{> _loginButtonsMessages "" }}

  {{#if showTroubleshooting}}
    {{> _loginButtonsSeparator "" }}
    <a class="troubleshooting" href="https://docs.sandstorm.io/en/latest/administering/faq/" target="_blank">{{_ "accounts.loginButtons.loginButtonsList.troubleshooting"}}</a>
  {{/if}}

  {{#if showAbout}}
    {{#linkTo route="about"}}{{_ "accounts.loginButtons.loginButtonsList.about"}}{{/linkTo}}
  {{/if}}
  </div>
</template>

<template name="oauthLoginButton">
  <button class="login oneclick {{data.name}}">
    {{_ "accounts.loginButtons.oauthLoginButton.with"}}{{data.displayName}}
  </button>
</template>

<template name="devLoginForm">
{{#let txt="accounts.loginButtons.devLoginForm"}}
  {{#if expanded}}
  <form class="dev login expanded">
    {{_ (con txt "label")}} <button type="button" title="{{_ (con txt "hint")}}" class="unexpand"> ▴ </button>
    <ul class="dev-credentials">
      <li><button type="button" class="login-dev-account" data-name="Alice Dev Admin"
                  data-is-admin="true">
          {{_ (con txt "alice")}}
      </button></li>
      <li><button type="button" class="login-dev-account" data-name="Bob Dev User">
          {{_ (con txt "bob")}}
      </button></li>
      <li><button type="button" class="login-dev-account" data-name="Carol Dev User">
          {{_ (con txt "carol")}}
      </button></li>
      <li><button type="button" class="login-dev-account" data-name="Dave Dev User">
          {{_ (con txt "dave")}}
      </button></li>
      <li class="custom-name">
        <input name="name" type="text" placeholder="{{_ (con txt "customPlaceholder")}}" required>
        <button type="submit">{{_ (con txt "customButton")}}</button>
      </li>
    </ul>
  </form>
  {{else}}
  <button class="dev login expand">
    {{_ (con txt "label")}} ▾
  </button>
  {{/if}}
{{/let}}
</template>

<template name="emailLoginForm">
  {{> emailAuthenticationForm linkingNewCredential=linkingNewCredential
      description=(_ "accounts.loginButtons.emailLoginForm.description")
      prompt="email" 
      sendButtonText=(_ "accounts.loginButtons.emailLoginForm.sendButtonText")
      loginId=loginId}}
</template>

<template name="emailAuthenticationForm">
{{#let txt="accounts.loginButtons.emailAuthenticationForm"}}
  <form class="email">
    {{description}}

    <label class="email {{#if awaitingToken}}hidden{{/if}}">{{prompt}}
      <span title="{{_ (con txt "hint")}}" class="info">{{_ "accounts.loginButtons.icon.info"}}</span>
      <input name="email" type="email" disabled={{disabled}} value={{loginId}}>
    </label>

    {{#with awaitingToken}}
    <p>{{_ (con txt "token.explanation") .}}</p>
    <label class="token">
      {{_ (con txt "token.label")}}
      <input name="token" type="text">
    </label>
    <div class="button-box">
      <button class="login token">{{_ (con txt "token.confirmButton")}}</button>
      <button type="reset" class="cancel">{{_ (con txt "token.cancelButton")}}</button>
    </div>
    {{else}}
    <div class="button-box">
      <button class="login email" disabled={{disabled}}>{{sendButtonText}}</button>
    </div>
    {{/with}}

    {{#if disabled}}
    <p>{{_ (con txt "disabled")}}</p>
    {{/if}}
  </form>
{{/let}}
</template>

<template name="ldapLoginForm">
{{#let txt="accounts.loginButtons.ldapLoginForm"}}
  <form class="ldap">
    {{loginProviderLabel}}

    <label class="username">{{_ (con txt "username.label")}}
      <span title="{{_ (con txt "username.hint")}}" class="info">{{_ "accounts.loginButtons.icon.info"}}</span>
      <input name="username" type="text" value="{{loginId}}">
    </label>

    <label class="password">{{_ (con txt "password.label")}}
      <span title="{{_ (con txt "password.hint")}}" class="info">{{_ "accounts.loginButtons.icon.info"}}</span>
      <input name="password" type="password">
    </label>
    <div class="button-box">
      <button class="login email">{{_ (con txt "loginButton")}}</button>
    </div>
  </form>
{{/let}}
</template>

<template name="samlLoginForm">
  <button class="login oneclick saml">
    {{loginProviderLabel}}
  </button>
</template>

<template name="_loginButtonsSeparator">
  <div class="or">
    <span class="hline">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
    <span class="or-text">{{_ "accounts.loginButtons._loginButtonsSeparator.or"}}</span>
    <span class="hline">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
  </div>
</template>
